(symbols "invokeMethodHandles" 'pico)

(local *Exceptions)

(setq *Exceptions
  '("IllegalArgumentException"
    "WrongMethodTypeException"
    "ClassCastException"
    "ArrayIndexOutOfBoundsException") )

(when (>= (javaVersion T) (1 7) )
  (de pico~invokeMethodHandles (MethodHandles . @)
    (thread
      (quote (MethodHandle)
        (when (or
                (thread MethodHandle
                  (java+ "isVarargsCollector")
                  java)
                (thread MethodHandle
                  (java+ "type")
                  (java "parameterCount")
                  java
                  (= (length (rest) ) ) ) )
          (catch+ *Exceptions
            (thread MethodHandle
              list
              (append (rest) )
              (apply+ invokeMethodHandle)
              cons) ) ) )
      (pick MethodHandles)
      car) ) )